<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <link rel="stylesheet" href="/static/css/hui.css">
</head>

<body>
    <header class="hui-header">
        <div id="hui-back"></div>
        <h1>登陆页面&nbsp;&nbsp;&nbsp;&nbsp;</h1>
    </header>
    <div class="hui-wrap">
        <form id="form1" class="hui-form" style="padding:28px 10px;" enctype="multipart/form-data">

            <div class="hui-form-items">
                <div class="hui-form-items-title">手机号码</div>
                <input type="tel" class="hui-input" placeholder="请输入手机号码" id="account">
            </div>

            <div class="hui-form-items">
                <div class="hui-form-items-title">登录密码</div>
                <input type="password" class="hui-input hui-pwd-eye" placeholder="登录密码" id="pwd">
                <div class="hui-pwd-eyes" onclick="hui.eyesChange(this);"></div>
            </div>
            <div style="padding:15px 8px;">
                <button type="button" class="hui-button hui-button-large hui-primary" id="loginBtn">登陆</button>
            </div>
            <div style="padding:15px 8px;">
                <a href="/regist/" class="hui-button hui-button-large">注册</a>
            </div>
            <div style="text-align: center">
                <a href="/forgetPW/" >忘记密码?</a>
            </div>

        </form>

    </div>

    <script type="text/javascript" src="/static/js/hui.js"></script>
    <script type="text/javascript" src="/static/js/hui-form.js"></script>


    <script>
        hui("#loginBtn").click(function (e) {
            var account = hui('#account').val();
            var paw = hui('#pwd').val();
            if (!account && !/1[3|4|5|7|8|9]\d{9}/.test(account)) {
                hui.toast('请输入正确手机号');
            } else if (!paw) {
                hui.toast('密码不为空');
            } else {
                hui.ajax({
                    url: 'http://127.0.0.1:5000/login/',
                    data: {
                        account: account,
                        paw: paw
                    },
                    type: 'POST',
                    cache: false,
                    // dataType: 'json',
                    'backType' : "JSON",
                    beforeSend: function () { hui.loading(); },
                    complete: function () { hui.closeLoading(); },
                    success: function (data) {

                        if (data.code != 0) {
                            hui.iconToast(data.message);

                            window.location.href = "http://127.0.0.1:5000";
                        } else {
                            hui.iconToast(data.message, 'error');


                        }

                    }

                })
            }
        });
    </script>
</body>

</html>